<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-card title="单位信息">
          <a-col :span="8">
            <a-form-model-item label="采购人名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="purchaserName">
              <a-input v-model="model.purchaserName" placeholder="请输入采购人名称"  ></a-input>
            </a-form-model-item>
          </a-col> 
          <a-col :span="8">
            <a-form-model-item label="采购项目联系人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="purchaserconnector">
              <a-input v-model="model.purchaserconnector" placeholder="请输入采购项目联系人"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="采购项目联系人电话" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="purchasercontactinformation">
              <a-input v-model="model.purchasercontactinformation" placeholder="请输入采购项目联系人电话"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="采购项目联系人手机" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="purchaserconnectormobile">
              <a-input v-model="model.purchaserconnectormobile" placeholder="请输入采购项目联系人手机"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="采购项目联系人职务" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="purchaserconnectorzhiwu">
              <a-input v-model="model.purchaserconnectorzhiwu" placeholder="请输入采购项目联系人职务"  ></a-input>
            </a-form-model-item>
          </a-col>

          <a-col :span="8">
            <a-form-model-item label="投资项目统一代码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="investProjectCode">
              <a-input v-model="model.investProjectCode" placeholder="请输入投资项目统一代码"  ></a-input>
            </a-form-model-item>
          </a-col> 
        </a-card>
        <a-card title="项目信息" style="margin-top: 15px" >
            <a-col :span="8">
            <a-form-model-item label="项目编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="purchaseProjectCode">
              <a-input v-model="model.purchaseProjectCode" placeholder="请输入项目编号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="项目名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="purchaseProjectName">
              <a-input v-model="model.purchaseProjectName" placeholder="请输入项目名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="项目类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tenderProjectType">
              <j-dict-select-tag type="list" v-model="model.tenderProjectType" dictCode="cg_project_type" placeholder="请选择项目类型" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="项目预算" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="programBudget">
              <a-input-number v-model="model.programBudget" placeholder="请输入项目预算" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <!-- <a-col :span="8">
            <a-form-model-item label="预算金额币种" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="budgetCurrency">
              <a-input v-model="model.budgetCurrency" placeholder="请输入预算金额币种"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="预算金额单位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="unitBudget">
              <a-input v-model="model.unitBudget" placeholder="请输入预算金额单位"  ></a-input>
            </a-form-model-item>
          </a-col> -->
          <a-col :span="8">
            <a-form-model-item label="是否ppp项目" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isProject">
              <j-dict-select-tag type="radio" v-model="model.isProject" dictCode="yn" placeholder="请选择是否ppp项目" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="采购方式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="purchaserMode">
              <j-dict-select-tag type="list" v-model="model.purchaserMode" dictCode="cg_type" placeholder="请选择采购方式" />
            </a-form-model-item>
          </a-col>
           <a-col :span="8">
            <a-form-model-item label="项目所在行政区划" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="regioncode">
              <j-dict-select-tag type="list" v-model="model.regioncode" dictCode="sys_xz_area" placeholder="请选择项目所在行政区划" />
            </a-form-model-item>
          </a-col> 
          <a-col :span="8">
            <a-form-model-item label="项目行业分类" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="industriestype">
               <j-category-select v-model="model.industriestype" pcode="A04" />
            </a-form-model-item>
          </a-col>
           <a-col :span="24">
            <a-form-model-item label="项目地址"  :labelCol="{ lg: { span: 3 }, sm: { span: 4 } }"
                :wrapperCol="{ lg: { span: 21 }, sm: { span: 20 } }" prop="projectaddress">
              <a-textarea v-model="model.projectaddress" rows="4" placeholder="请输入项目地址" />
            </a-form-model-item>
          </a-col>
        </a-card>
        <a-card title="采购情况"  style="margin-top: 15px" >
          <a-col :span="24">
            <a-form-model-item label="采购内容"   :labelCol="{ lg: { span: 3 }, sm: { span: 4 } }"
                :wrapperCol="{ lg: { span: 21 }, sm: { span: 20 } }" prop="purchaserContent">
              <a-textarea v-model="model.purchaserContent" rows="4" placeholder="请输入采购内容" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="采购组织形式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="purchaserOrganizeForm">
              <j-dict-select-tag type="list" v-model="model.purchaserOrganizeForm" dictCode="cg_org_type" placeholder="请选择采购组织形式" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="采购代理机构名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="purchaserAgencyName">
              <a-input v-model="model.purchaserAgencyName" placeholder="请输入采购代理机构名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="采购代理机构代码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="purchaserAgencyCode">
              <a-input v-model="model.purchaserAgencyCode" placeholder="请输入采购代理机构代码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="采购代理机构角色" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="purchaserAgencyRole">
              <a-input v-model="model.purchaserAgencyRole" placeholder="请输入采购代理机构角色"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="采购代理机构联系人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="purchaserAgencyConnector">
              <a-input v-model="model.purchaserAgencyConnector" placeholder="请输入采购代理机构联系人"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="采购代理机构联系电话" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="purchaserAgencyInformation">
              <a-input v-model="model.purchaserAgencyInformation" placeholder="请输入采购代理机构联系电话"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="采购项目子包编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="purchaseSectionCode">
              <a-input v-model="model.purchaseSectionCode" placeholder="请输入采购项目子包编号"  ></a-input>
            </a-form-model-item>
          </a-col> 
          <a-col :span="8">
            <a-form-model-item label="采购项目子包名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="purchaseSectionName">
              <a-input v-model="model.purchaseSectionName" placeholder="请输入采购项目子包名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="监督部门名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="superviseDeptName">
              <a-input v-model="model.superviseDeptName" placeholder="请输入监督部门名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="监督部门代码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="superviseDeptCode">
              <a-input v-model="model.superviseDeptCode" placeholder="请输入监督部门代码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="审核部门名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="approveDeptName">
              <a-input v-model="model.approveDeptName" placeholder="请输入审核部门名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="审核部门代码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="approveDeptCode">
              <a-input v-model="model.approveDeptCode" placeholder="请输入审核部门代码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="统一交易标识码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="unifiedDealCode">
              <a-input v-model="model.unifiedDealCode" placeholder="请输入统一交易标识码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="交易系统标识码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="platformCode">
              <a-input v-model="model.platformCode" placeholder="请输入交易系统标识码"  ></a-input>
            </a-form-model-item>
          </a-col>
         
          <a-col :span="8">
            <a-form-model-item label="项目批准备案文号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="projectapprovalrecordno">
              <a-input v-model="model.projectapprovalrecordno" placeholder="请输入项目批准备案文号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="资金来源" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fundsource">
              <j-dict-select-tag type="list" v-model="model.fundsource" dictCode="cg_capital_source" placeholder="请选择资金来源" />
            </a-form-model-item>
          </a-col>
          
          <a-col :span="8">
            <a-form-model-item label="财政委托编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="financeentrustcode">
              <a-input v-model="model.financeentrustcode" placeholder="请输入财政委托编号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="项目类别" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="zhaobiaolbXlCode">
              <a-input v-model="model.zhaobiaolbXlCode" placeholder="请输入项目类别"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="招标模式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="xiangmumoshi">
              <a-input v-model="model.xiangmumoshi" placeholder="请输入招标模式"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="是否基础设施和公用事业特许经营权" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isjcandsy">
              <j-dict-select-tag type="radio" v-model="model.isjcandsy" dictCode="yn" placeholder="请选择是否基础设施和公用事业特许经营权" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="是否包含机电国际招投标" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isgjzb">
              <j-dict-select-tag type="radio" v-model="model.isgjzb" dictCode="yn" placeholder="请选择是否包含机电国际招投标" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="监管办专管员" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="supervisionname">
              <a-input v-model="model.supervisionname" placeholder="请输入监管办专管员"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="监管办专管员联系电话" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="supervisionnametel">
              <a-input v-model="model.supervisionnametel" placeholder="请输入监管办专管员联系电话"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="归口业务处室" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="econormicname">
              <a-input v-model="model.econormicname" placeholder="请输入归口业务处室"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="资格审查方式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="zigeshenchatype">
              <a-input v-model="model.zigeshenchatype" placeholder="请输入资格审查方式"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="自行采购核准文号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="zixingwenhao">
              <a-input v-model="model.zixingwenhao" placeholder="请输入自行采购核准文号"  ></a-input>
            </a-form-model-item>
          </a-col>
              </a-card>
        </a-row>
      </a-form-model>
    </j-form-container>
    <div style="margin-top: 15px">
      <ex-operation-record ref="exOperationRecord" :module="'exPurchaseProject'" :entryId="model.id"></ex-operation-record>
    </div>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'
  import ExOperationRecord from '@/views/exOperationRecord/Index'

  export default {
    name: 'ExPurchaseProjectForm',
    components: {
      ExOperationRecord
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
        xs: { span: 24 },
        sm: { span: 9 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 15 },
      },
        confirmLoading: false,
        validatorRules: {
           purchaseProjectCode: [
              { required: true, message: '请输入采购项目编号!'},
           ],
           purchaseProjectName: [
              { required: true, message: '请输入采购项目名称!'},
           ],
           tenderProjectType: [
              { required: true, message: '请输入采购项目类型!'},
           ],
           purchaserName: [
              { required: true, message: '请输入采购人名称!'},
           ],
           purchaserCode: [
              { required: true, message: '请输入采购人代码!'},
           ],
           purchaserRole: [
              { required: true, message: '请输入采购人角色!'},
           ],
           programBudget: [
              { required: false},
              { pattern: /^(([1-9][0-9]*)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/, message: '请输入正确的金额!'},
           ],
           purchaserMode: [
              { required: true, message: '请输入采购方式!'},
           ],
           purchaserOrganizeForm: [
              { required: true, message: '请输入采购组织形式!'},
           ],
           purchaserAgencyName: [
              { required: true, message: '请输入采购代理机构名称!'},
           ],
           purchaserAgencyCode: [
              { required: true, message: '请输入采购代理机构代码!'},
           ],
           purchaserAgencyRole: [
              { required: true, message: '请输入采购代理机构角色!'},
           ],
           purchaseSectionCode: [
              { required: true, message: '请输入采购项目子包编号!'},
           ],
           purchaseSectionName: [
              { required: true, message: '请输入采购项目子包名称!'},
           ],
           superviseDeptName: [
              { required: true, message: '请输入监督部门名称!'},
           ],
           approveDeptName: [
              { required: true, message: '请输入审核部门名称!'},
           ],
           unifiedDealCode: [
              { required: true, message: '请输入统一交易标识码!'},
           ],
           platformCode: [
              { required: true, message: '请输入交易系统标识码!'},
           ],
           regioncode: [
              { required: true, message: '请输入项目所在行政区划代码!'},
           ],
           projectaddress: [
              { required: true, message: '请输入项目地址!'},
           ],
           industriestype: [
              { required: true, message: '请输入项目行业分类!'},
           ],
           fundsource: [
              { required: true, message: '请输入资金来源!'},
           ],
           purchaserconnector: [
              { required: true, message: '请输入采购项目联系人!'},
           ],
           purchasercontactinformation: [
              { required: true, message: '请输入采购项目联系人电话!'},
           ],
           purchaserconnectormobile: [
              { required: true, message: '请输入采购项目联系人手机!'},
           ],
           purchaserconnectorzhiwu: [
              { required: true, message: '请输入采购项目联系人职务!'},
           ],
           isjcandsy: [
              { required: true, message: '请输入是否基础设施和公用事业特许经营权!'},
           ],
           isgjzb: [
              { required: true, message: '请输入是否包含机电国际招投标!'},
           ],
           zigeshenchatype: [
              { required: true, message: '请输入资格审查方式!'},
           ],
        },
        url: {
          add: "/exPurchaseProject/exPurchaseProject/add",
          edit: "/exPurchaseProject/exPurchaseProject/edit",
          queryById: "/exPurchaseProject/exPurchaseProject/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>